package kr.hkit.powerjava.chapter21.work;

import java.io.NotActiveException;
import java.util.Scanner;

class NotFoundException extends Exception {
	public NotFoundException() {
		super("찾고자 하는 숫자가 배열에 존재하지 않습니다.");
	}
}

class ArraySearch {
	private int[] arr;
	private int SIZE;
	private int searchKey;
	Scanner input = new Scanner(System.in);

	public void init(int size) {
		this.SIZE = size;
		arr = new int[SIZE];
	}

	public void inputArray() {
		for (int i = 0; i < arr.length; i++) {
			arr[i] = input.nextInt();
		}

		for (int i = 0; i < arr.length; i++) {
			System.out.print("arr[" + i + "] = " + arr[i] + "   ");
		}
		System.out.println();
	}

	public int searchKey(int searchKey) throws NotFoundException {
		int equal = 0;
		for (int i = 0; i < arr.length; i++) {
			if (arr[i] == searchKey) {
				equal = arr[i];
				break;
			}
		}

		if (equal == searchKey) {
			System.out.println("Search!"+equal);
			return equal;
		} else {
			throw new NotFoundException();
		}

	}
}

public class ArraySearchTest {
	public static void main(String[] args) {
		ArraySearch arr = new ArraySearch();
		arr.init(5);
		arr.inputArray();
		try {
			arr.searchKey(37);
		} catch (NotFoundException e) {
			e.printStackTrace();
		}

	}
}
